<script>
	import {
		Route
	} from '@/plugins/router/router.js';
	import Router from '@/plugins/router';
	import Modules from '@/plugins/modules'
	import Utils from '@/uni_modules/yingbing-ui/js_sdk/util.js'
	import Config from '@/assets/js/config.js'
	import Business from '@/assets/js/business.js'
	import AppUpdate from '@/assets/update/appUpdate'
	export default {
		globalData: {
			$Router: Router,
			$Route: new Route(),
			$modules: Modules,
			$utils: Utils,
			$config: Config,
			$business: Business,
			backTime: 0,
			isReturnBack: false
		},
		onLaunch: function() {
			console.log('App Launch')
			// #ifdef APP-PLUS
			AppUpdate()
			plus.navigator.setFullscreen(false);
			plus.screen.lockOrientation('portrait-primary');
			const toast = plus.nativeUI.toast;
			const quit = plus.runtime.quit
			//重写退出方法
			plus.runtime.quit = (function () {
				const pages = getCurrentPages()
				if ( getApp().globalData.backTime == 1 ) {
					pages[pages.length-1].$vm.$refs.dialog.hide()
				} else if ( getApp().globalData.backTime == 2 ) {
					quit()
				} else {
					getApp().globalData.backTime++
					pages[pages.length-1].$vm.isBack()
				}
			})
			//重写toast方法如果内容为 ‘再次返回退出应用’ 就隐藏应用，其他正常toast
			plus.nativeUI.toast = (function(message, styles) {
				if (message == '再按一次退出应用' || message == '再按一次退出應用') {
					const pages = getCurrentPages()
					if ( getApp().globalData.backTime > 0 ) {
						// quit()
						pages[pages.length-1].$vm.$refs.dialog.hide()
					} else {
						getApp().globalData.backTime++
						pages[pages.length-1].$vm.isBack()
					}
				} else {
					toast(message, styles)
				}
			});
			// #endif
		},
		onShow: function() {
			console.log('App Show')
			getApp().globalData.isReturnBack = false
		},
		onHide: function() {
			console.log('App Hide')
			uni.$emit('app-hide');
			getApp().globalData.isReturnBack = true
		}
	}
</script>

<style>
	@import url(uni_modules/yingbing-ui/css/common.css);

	/*每个页面公共css */
	/* #ifdef APP-VUE */
	page {
		background: #333333;
	}

	/* #endif */
	
	.nav-bar {
		height: 100rpx;
	}
	.opac-actived:active {
		opacity: 0.5;
	}

	.margin-gap {
		margin-left: 30rpx;
		margin-right: 30rpx;
	}

	.padding-gap {
		padding-left: 30rpx;
		padding-right: 30rpx;
	}
</style>
